package com.scqzy.shengchunqiang.sword2offer.day13;

/**
 * @Description: 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
 * @Author 盛春强
 * @Date 2021/8/19 17:39
 */
public class Exchange {
    public int[] exchange(int[] nums) {
        int left = 0;
        int right = nums.length-1;
        int[] res = new int[nums.length];
        for (int num : nums) {
            if (num % 2 == 1) {
                res[left++] = num;
            } else {
                res[right--] = num;
            }
        }
        return res;
    }
}
